package com.example.mac.yuejian14.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import com.example.mac.yuejian14.R;
import com.example.mac.yuejian14.activity.ActivityDetailActivity;
import com.example.mac.yuejian14.bean.ActivityBean;

/**
<<<<<<< HEAD
 * Created by Administrator on 2017/10/25.
=======
 * Created by GaoNa on 2018/10/8.
>>>>>>> 4629567011ce192c56b08540254859f8a556460d
 */

public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;

    private LayoutInflater mLayoutInflaterm;
    public ActivityListAdapter(Context mContext,List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflaterm = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflaterm.from(parent.getContext())
                .inflate(R.layout.cardview_wonder, parent, false);
        return new ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final ActivityBean entity = (ActivityBean) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.activityname.setText(entity.getActname());
        String actpic =  "http://10.0.2.2/neu12_yuejian/Public/Uploads/photo/"+entity.getActpic();

        Picasso.with(mContext).load(actpic).into(viewHolder.imageactivity);
        if (viewHolder.imageactivity.getDrawable()==null){
            viewHolder.imageactivity.setImageResource(R.drawable.no_pic);
        }

        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("actid",entity.getActid());
                bundle.putString("actname",entity.getActname());
                bundle.putInt("actcost",entity.getActcost());
                bundle.putString("actaddress",entity.getActaddress());
                bundle.putString("acttime",entity.getActtime());
                bundle.putString("actpic",entity.getActpic());
                bundle.putString("actcall",entity.getActcall());
                bundle.putString("actintro",entity.getActintro());
                Intent intent=new Intent(mContext, ActivityDetailActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {

        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageactivity;
        TextView activityname;
        public ViewHolder(View itemView){
            super(itemView);
            activityname = (TextView) itemView.findViewById(R.id.activity_name);
            imageactivity = (ImageView) itemView.findViewById(R.id.activity_pic);
        }
    }

}
